home *** CD-ROM | disk | FTP | other *** search
/ Savor the Moment - Entert…ing Without Reservations / Savoe the Moment - Entertaining Without Reservations.iso / pc / Frencharm.dxr / 00032_Display Text.ls < prev    next >
Encoding:
Text File  |  1999-10-03  |  9.2 KB  |  203 lines

  1. property spriteNum, getPDLError, myDisplayType, mySprite, myMember, myWidthAdjust, myHeightAdjust, myOffStageLoc
  2.  
  3. on getBehaviorDescription me
  4.   return "DISPLAY TEXT" & RETURN & RETURN & "This behavior allows you to display a given string in a Field or Text member.  Use it with the 'Tooltip' and 'Hypertext - Display Status' behaviors which need a Field or Text member in which to display their information.  Or create your own custom Lingo to display runtime information, such as the position of the mouse." & RETURN & RETURN & "This behavior waits for Lingo commands to tell it what to do.  It is not active by itself." & RETURN & RETURN & "You can choose between two display types: tooltip and status bar." & RETURN & RETURN & "The TOOLTIP type of display will make the Field or Text member resize itself to fit the text, and disappear when it is empty.  You can set the tooltip type display to appear at any position on the stage, for example: under the cursor.  If no position is sent to the sprite, it will appear at the top left corner of the Stage.  See the 'Tooltip' behavior for more details." & RETURN & RETURN & "If you wish to display several lines of text, you must use RETURN characters to define the line breaks.  An empty tooltip sprite will move off-stage to hide.  It is recommended to place it off-stage before it is used, in case it causes a brief flash on the screen." & RETURN & RETURN & "The STATUS BAR type of display will appear on Stage at all times.  It will not resize or change position.  Any positional information sent to this sprite will be ignored if it is set to act as a status bar.  If the text is too long to appear in the member of the current sprite, a scrollbar will appear.  You do not need to divide the text with RETURN characters.  If you think that a scrollbar may be necessary, make sure that the Field or Text member is sufficiently tall for the scroll arrows to operate correctly." & RETURN & RETURN & "Set the font size and other characteristics of Field or Text member to customize the appearance of the message." & RETURN & RETURN & "Be sure to give the Text or Field member a name.  It may be emptied by this behavior.  Director 7 automatically erases nameless empty members." & RETURN & RETURN & "PERMITTED MEMBER TYPES:" & RETURN & "Field and Text members" & RETURN & RETURN & "PARAMETERS:" & RETURN & "* Display type:" & RETURN & "  - Tooltip (appears near the cursor on rollover)" & RETURN & "  - Status bar (appears in a fixed position at all times)" & RETURN & RETURN & "ASSOCIATED BEHAVIORS:" & RETURN & "+ Tooltip" & RETURN & "+ Source Status" & RETURN & "+ Hypertext - Display Status" & RETURN & RETURN & "PUBLIC METHODS:" & RETURN & "=> Set the text to display (and the position of the sprite)"
  5. end
  6.  
  7. on getBehaviorTooltip me
  8.   vTip = "Use with Field or Text members." & RETURN & RETURN
  9.   vTip = vTip & "This behavior waits for a message from another" & RETURN
  10.   vTip = vTip & "behavior or custom handler to display a character" & RETURN
  11.   vTip = vTip & "string.  It is intended to be used with the 'Tooltip'," & RETURN
  12.   vTip = vTip & "'Source Status' and 'Hypertext - Display Status' " & RETURN
  13.   vTip = vTip & "behaviors to create a status bar or a tooltip " & RETURN
  14.   vTip = vTip & "under the cursor."
  15.   return vTip
  16. end
  17.  
  18. on beginSprite me
  19.   Initialize(me)
  20. end
  21.  
  22. on endSprite me
  23.   mySprite.visible = 1
  24. end
  25.  
  26. on Initialize me
  27.   mySprite = sprite(me.spriteNum)
  28.   myMember = mySprite.member
  29.   memberType = myMember.type
  30.   case memberType of
  31.     #field, #text:
  32.     otherwise:
  33.       return ErrorAlert(me, #invalidMemberType, memberType)
  34.   end case
  35.   myDisplayType = symbol(myDisplayType)
  36.   if myMember.type = #field then
  37.     myWidthAdjust = (myMember.margin + myMember.border) * 2
  38.     myHeightAdjust = myMember.margin + (myMember.border * 2)
  39.   else
  40.     myWidthAdjust = 0
  41.     myHeightAdjust = 0
  42.   end if
  43.   myMember.text = EMPTY
  44.   if myDisplayType = #Tooltip then
  45.     myMember.boxType = #fixed
  46.     myOffStageLoc = point(999, 999)
  47.     mySprite.loc = myOffStageLoc
  48.   end if
  49. end
  50.  
  51. on BestRect me, theString
  52.   myMember.rect = rect(0, 0, 8000, 0)
  53.   myMember.text = theString
  54.   BestRect = myMember.rect
  55.   theLine = the number of lines in theString
  56.   theWidth = 0
  57.   checkedChars = 0
  58.   repeat while theLine
  59.     endOfLine = offset(RETURN, theString)
  60.     if not endOfLine then
  61.       endOfLine = the number of chars in theString + 1
  62.       myMember.text = myMember.text & RETURN
  63.     end if
  64.     checkedChars = checkedChars + endOfLine
  65.     endPoint = charPosToLoc(myMember, checkedChars)
  66.     lineWidth = endPoint[1]
  67.     if lineWidth > theWidth then
  68.       theWidth = lineWidth
  69.     end if
  70.     delete char 1 to endOfLine of theString
  71.     theLine = theLine - 1
  72.   end repeat
  73.   lastChar = myMember.char.count
  74.   lastCharLoc = charPosToLoc(myMember, lastChar)
  75.   theHeight = lastCharLoc[2]
  76.   BestRect[3] = theWidth + 1
  77.   BestRect[4] = theHeight + 1
  78.   return BestRect
  79. end
  80.  
  81. on GetTopLeft me, theLoc, theAlignment, memberRect
  82.   case theAlignment of
  83.     #bottomCenter:
  84.       return theLoc - [memberRect.width / 2, memberRect.height]
  85.     #bottomRight:
  86.       return theLoc - [memberRect.width, memberRect.height]
  87.     #bottomLeft:
  88.       return theLoc - [0, memberRect.height]
  89.     #center:
  90.       return theLoc - [memberRect.width / 2, memberRect.height / 2]
  91.     #topCenter:
  92.       return theLoc - [memberRect.width / 2, 0]
  93.     #topRight:
  94.       return theLoc - [memberRect.width, 0]
  95.     otherwise:
  96.       return theLoc
  97.   end case
  98. end
  99.  
  100. on DisplayText_Enroll me, enrollList
  101.   if ilk(enrollList) <> #list then
  102.     return me
  103.   end if
  104.   if not enrollList.count() then
  105.     enrollList.append(me)
  106.   else
  107.   end if
  108.   return enrollList
  109. end
  110.  
  111. on DisplayText_SetText me, theString, theLoc, theAlignment
  112.   if not stringp(theString) then
  113.     ErrorAlert(me, #invalidString, theString)
  114.     theString = string(theString)
  115.   else
  116.     case ilk(theLoc) of
  117.       #void, #point:
  118.       otherwise:
  119.         ErrorAlert(me, #invalidPoint, theLoc)
  120.         theLoc = point(0, 0)
  121.     end case
  122.   end if
  123.   if (theString = EMPTY) and (myDisplayType = #Tooltip) then
  124.     mySprite.loc = myOffStageLoc
  125.   else
  126.     myMember.text = theString
  127.     if myDisplayType = #Tooltip then
  128.       memberRect = BestRect(me, theString)
  129.       myMember.rect = memberRect
  130.     else
  131.       memberRect = myMember.rect
  132.     end if
  133.     memberRect = memberRect + [0, 0, myWidthAdjust, myHeightAdjust]
  134.     if myDisplayType = #Tooltip then
  135.       if ilk(theLoc) <> #point then
  136.         theLoc = point(0, 0)
  137.       end if
  138.       theLoc = GetTopLeft(me, theLoc, theAlignment, memberRect)
  139.       stageWidth = (the activeWindow).rect.right - (the activeWindow).rect.left
  140.       stageHeight = (the activeWindow).rect.bottom - (the activeWindow).rect.top
  141.       maxH = stageWidth - memberRect.width
  142.       maxV = stageHeight - memberRect.height
  143.       theLoc[1] = max(0, min(theLoc[1], maxH))
  144.       theLoc[2] = max(0, min(theLoc[2], maxV))
  145.       theLoc = theLoc + myMember.regPoint
  146.       mySprite.loc = theLoc
  147.     else
  148.       lastChar = theString.char.count
  149.       textHeight = charPosToLoc(myMember, lastChar)[2]
  150.       if textHeight > mySprite.height then
  151.         myMember.boxType = #scroll
  152.       else
  153.         myMember.boxType = #fixed
  154.       end if
  155.     end if
  156.   end if
  157. end
  158.  
  159. on DisplayText_GetReference me
  160.   return me
  161. end
  162.  
  163. on ErrorAlert me, theError, data
  164.   case theError of
  165.     #getPDLError:
  166.       alert("Error: This behavior works only with Field and Text members." & RETURN & RETURN & "Hit OK and then delete this behavior from the sprite." & RETURN & RETURN & "For more information on deleting Behaviors, see the Help system.")
  167.       if the optionDown then
  168.         return [#getPDLError: [#comment: "ERROR:   Wrong member type.   Click 'Cancel'." & RETURN & "             Use only with Field and Text members.", #format: #string, #range: [EMPTY], #default: EMPTY]]
  169.       end if
  170.     otherwise:
  171.       case theError of
  172.         #invalidMemberType:
  173.           behaviorName = string(me)
  174.           delete word 1 of behaviorName
  175.           delete char -30001 of behaviorName
  176.           delete char -30001 of behaviorName
  177.           alert("BEHAVIOR ERROR: Frame " & the frame & ", Sprite " & me.spriteNum & RETURN & RETURN & "Behavior " & behaviorName & " only works with Field and Text members." & RETURN & RETURN & "Current member type = #" & data)
  178.           halt()
  179.         #invalidString:
  180.           if the runMode = "Author" then
  181.             alert("BEHAVIOR ERROR: Frame " & the frame & ", Sprite " & me.spriteNum & RETURN & "Behavior " & behaviorName & RETURN & RETURN & "The DisplayText_SetText handler could not treat the following as a string:" & RETURN & RETURN & data)
  182.           end if
  183.         #invalidPoint:
  184.           if the runMode = "Author" then
  185.             alert("BEHAVIOR ERROR: Frame " & the frame & ", Sprite " & me.spriteNum & RETURN & "Behavior " & behaviorName & RETURN & RETURN & "The DisplayText_SetText handler could not treat the following as a point:" & RETURN & RETURN & data)
  186.           end if
  187.       end case
  188.   end case
  189. end
  190.  
  191. on getPropertyDescriptionList me
  192.   if not (the currentSpriteNum) then
  193.     exit
  194.   end if
  195.   theMember = sprite(the currentSpriteNum).member
  196.   case theMember.type of
  197.     #field, #text:
  198.     otherwise:
  199.       return ErrorAlert(me, #getPDLError)
  200.   end case
  201.   return [#myDisplayType: [#comment: "Display Text sprite behaves as a:", #format: #symbol, #range: ["status bar (fixed size and position)", "tooltip (dynamic size and position)"], #default: "in a fixed position (status bar)"]]
  202. end
  203.